package com.example.demo.controller;

import com.example.demo.model.vo.InquiryAddVo;
import com.example.demo.model.vo.InquiryVo;
import com.example.demo.service.InquiryService;
import com.example.demo.util.Result;
import com.example.demo.util.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * Created by Administrator on 2018/10/26 0026.
 */
@RestController
public class InquiryController {
    @Autowired
    private InquiryService inquiryService;
    @GetMapping("/inquiry/selectById")
    public Result<InquiryVo> selectById(@RequestParam("id") Integer id){
        return inquiryService.selectById(id);
    }
    @PostMapping("/addInquiryTotal")
    public Result<InquiryVo> addInquiry(@RequestBody @Valid InquiryAddVo inquiryAddVo, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultVo.error("501",bindingResult.getFieldError().getDefaultMessage());
        }
        return inquiryService.addInquiry(inquiryAddVo);
    }

}
